package com.example.demo.service.impl;

import com.example.demo.dao.StudentDao;
import com.example.demo.domain.Student;
import com.example.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentDao studentDao;

    @Override
    public List<Student> getAll() {
        return studentDao.getAll();
    }


    @Override
    public List<Student> findAll() {
        return studentDao.findAll();
    }

    @Override
    public Student getOne(String sid){
        return studentDao.getOne(sid);
    }


    @Override
    public List<Student> getAll2() {
        return studentDao.getAll2();
    }

    @Override
    public int insertStu(Student student) {
        int i;
        try {
            studentDao.insertStu(student);
            i=1;
        }catch (Exception e){
            i=0;
            System.out.println(e.fillInStackTrace());
        }
        return i;
    }


    @Override
    public int insertStuList(List<Student> list) {
        int i;
        try {
            studentDao.insertStuList(list);
            i=1;
        }catch (Exception e){
            i=0;
            System.out.println(e.fillInStackTrace());
        }
        return i;
    }

    @Override
    public int deleteStu(String sid) {
        int i;
        try {
            studentDao.deleteStu(sid);
            i=1;
        }catch (Exception e){
            i=0;
            System.out.println(e.fillInStackTrace());
        }
        return i;
    }



    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
//    @Transactional
    public int deleteStuList(Set<String> set){
        int i;
        try {
            studentDao.deleteStuList(set);
            i=1;
        }catch (Exception e){
            i=0;
            System.out.println(e.fillInStackTrace());
        }
        return i;
    }

    @Override
    public int updateStu(Student student) {

        int i;
        try {
            studentDao.updateStu(student);
            i=1;
        }catch (Exception e){
            i=0;
            System.out.println(e.fillInStackTrace());
        }
        return i;
    }





}
